<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item> <i class="el-icon-shopping-bag-2"></i> 用户黑名单 </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <!-- <el-button type="primary" class="handle-del mr10" @click="addClick">新增</el-button> -->
        <el-date-picker class="mr10" type="daterange" range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd"
                        v-model="query.time">
        </el-date-picker>
        <el-input placeholder="请输入产品名称查询" class="handle-input mr10" v-model="query.souVal"></el-input>
        <el-button type="primary" icon="el-icon-search" @click="getTableList">搜索</el-button>
      </div>
      <el-table :data="tableData" border class="table" style="width: 100%" ref="multipleTable" header-cell-class-name="table-header"
                @selection-change="SelectionChange" v-loading="listLoad">
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column type="index" :index="tableIndex" label="序号" width="55" align="center"></el-table-column>
        <el-table-column prop="name" label="姓名"></el-table-column>
        <el-table-column prop="phone" label="电话"></el-table-column>
        <el-table-column label="性别">
          <template slot-scope="scope">
            {{scope.row.gender == 1 ? '男':'女'}}
          </template>
        </el-table-column>
        <el-table-column prop="dateOfBirth" label="出生日期"></el-table-column>
        <el-table-column fixed="right" label="操作" width="200" align="center">
          <template slot-scope="scope">
            <!-- <el-button type="text" icon="el-icon-edit" class="red">编辑</el-button> -->
            <el-button type="text" icon="el-icon-remove-outline" class="red" @click="delBlackList(scope.row.id)">移出黑名单</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination">
        <el-pagination background layout="total, prev, pager, next" :current-page="query.page" :page-size="query.limit" :total="page.totalCount"
                       :pager-count="5" @current-change="PageChange" @prev-click="PageChange" @next-click="PageChange"></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import { userBlackListData, userBlackListDel } from '../../../api/index';
export default {
  data() {
    return {
      listLoad: false,

      query: {
        page: 1,
        limit: 10,
        souVal: "",
        time: []
      },
      tableData: [],
      page: {
        totalCount: 0,
      },

    };
  },
  created() {
    this.getTableList();
  },
  methods: {
    //获取黑名单列表
    getTableList() {
      this.listLoad = true;
      let query = {
        limit: this.query.limit,
        page: this.query.page,
        endTime: this.query.time[1],
        startTime: this.query.time[0],
        kw: this.query.souVal,
      };
      userBlackListData(query).then((res) => {
        this.listLoad = false;
        if (res.code == 0) {
          this.tableData = res.list;
          this.page.totalCount = res.totalCount;
        } else {
          this.$message(res.msg);
        }
      })
    },
    //移除黑名单
    delBlackList(id) {
      this.listLoad = true;
      userBlackListDel({ biId: id }).then((res) => {
        this.listLoad = false;
        if (res.code == 0) {
          this.$message.success('删除成功');
          this.getTableList();
        } else {
          this.$message(res.msg);
        }
      })
    },
    //序号
    tableIndex(index) {
      return (this.query.page - 1) * this.query.limit + index + 1;
    },
    //翻页
    PageChange(num) {
      this.query.page = num;
      this.getTableList();
    },
    //选中
    SelectionChange() { },
  }
};
</script>

<style scoped>
/deep/ :focus {
    outline: 0;
}
.handle-input {
    width: 300px;
    display: inline-block;
}
.nameDrawer {
    padding: 30px;
}
.elSelect {
    width: 100%;
}
.upload-demo {
    height: 32px;
}
.heng-border {
    height: 0.5px;
    margin-bottom: 30px;
}
</style>
